package com.ht.controller;

import com.ht.bean.*;
import com.ht.service.PermissionService;
import com.ht.service.XtbbService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/xt")
public class XtbbController {
    @Resource
    private XtbbService xt;

    @Resource
    private PermissionService per;

    @RequestMapping("/list")
    public String list(){
        return "xtbblist";
    }



    //考核去查询
    @RequestMapping("/ygkhtolist")
    public String ygkhtolist(Model model){
        //查询部门表
        List<Emp>khlist=xt.ygkhemp();
        model.addAttribute("khlist",khlist);
        return "rckhbaobiao";
    }

    //考核查询
    @RequestMapping("/ygkhlist")
    @ResponseBody
    public Map ygkhlist(Integer page, Integer limit, Aduitlog aduitlog, Emp emp){
        List<Map> ygkhlist=xt.ygkhlist((page-1)*limit,limit,aduitlog,emp);
        System.out.println(ygkhlist.toString());
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",xt.ygkhcount(aduitlog,emp));//总页数
        map.put("data",ygkhlist);//数据
        return map;
    }




    //---------------------------------------------------------------------------------------------------------------
    //去员工请假
    @RequestMapping("/yaungtolist")
    public String yaungtolist(Model model){
        //查询部门表
        List<Dep>deps=per.litdepduijian();
        model.addAttribute("deps",deps);
        return "yuangonqinbiao";
    }

    //考核查询
    @RequestMapping("/yuanglist")
    @ResponseBody
    public Map yuanglist(Integer page, Integer limit, Emp emp,String yue){
        List<Map> ygkhlist=xt.lisyuan((page-1)*limit,limit,emp,yue);
        System.out.println(ygkhlist.toString());
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",xt.lisyuann(emp,yue));//总页数
        map.put("data",ygkhlist);//数据
        return map;
    }

    @RequestMapping("/yuanglton")
    @ResponseBody
    public Map yuanglton(){
        List<Map> data=xt.lisyuannn();
        Map map = new HashMap();
        List<String> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        for (Map studentes : data){
            list.add((String) studentes.get("depName"));
            list1.add(Integer.parseInt(studentes.get("shu").toString()));
        }
        System.out.println("jksaghdjas"+list+list1);
        map.put("month",list);//数据
        map.put("amount1",list1);//数据
        return map;
    }


    //--------------------------------------------------------------------------------------------------
    //日常考核

    //去考核页面

    //--------------------------------------------------------------------------------------------------
    //宿舍报表
    //去宿舍报表首页
    @RequestMapping("/toshuse")
    public String toshuse(Model model){
        model.addAttribute("lou",xt.lislou());
        return "shushebaobiao";
    }

    //宿舍报表的数据
    @RequestMapping("/shuse")
    @ResponseBody
    public Map yuanxi(int page, int limit, Studenthuor studenthuor, Model model, HttpSession session){
        Map map = new HashMap();
        List<Map> data = xt.sushelist((page - 1) * limit,limit,studenthuor);
        session.setAttribute("passssdsa",data);
        model.addAttribute("sum",xt.sumhecount(studenthuor));
        map.put("code",0);
        map.put("msg","成功");
        map.put("count",xt.sushecount(studenthuor));//总页数
        map.put("data",data);//数据
        return map;
    }

    //宿舍报表的数据
    @RequestMapping("/shuseton")
    @ResponseBody
    public Map shuseton(){
        Map map = new HashMap();
        List<Map> data = xt.sushelistt();
        List<String> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        for (Map studentes : data){
            list.add((String) studentes.get("floorName")+"栋");
            list1.add(Integer.parseInt(studentes.get("ren").toString()));
            list2.add(Integer.parseInt(studentes.get("kon").toString()));
        }
        System.out.println("jksaghdjas"+list+list1+list2);
        map.put("month",list);//数据
        map.put("amount1",list1);//数据
        map.put("amount2",list2);//数据
        return map;
    }


}
